﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using NUnit.Framework;
using Microsoft.SharePoint;
using SharePoint.Contrib.Extensions;

namespace NUnit.SharePointContrib
{
    [TestFixture]
    public class SPFieldCollectionExtensionsTest
    {
        SPSite sitecollection = null;
        SPWeb root = null;

        [SetUp]
        public void Init()
        {
            if (SharePoint.TryFindSiteCollection(out sitecollection))
            {
                root = sitecollection.RootWeb;
            }
        }

        [TearDown]
        public void Dispose()
        {
            sitecollection.Dispose();
        }

        [Test]
        public void CanCastToSPFieldCanFailWithWrongFieldName()
        {
            SPFieldDateTime foo = root.Fields.Field<SPFieldDateTime>("foobar");
            Assert.That(foo, Is.Null);
        }

        [Test]
        public void CanCastToSPFieldCanFailWithWrongFieldType()
        {
            SPFieldBoolean StartDate = root.Fields.Field<SPFieldBoolean>("StartDate");
            Assert.That(StartDate, Is.Null);
        }

        [Test]
        public void CanCastToSPField()
        {
            SPField StartDate = root.Fields.Field<SPField>("StartDate");
            Assert.That(StartDate, Is.Not.Null);
        }

        [Test]
        public void CanCastToSPDateTimeField()
        {
            SPFieldDateTime StartDate = root.Fields.Field<SPFieldDateTime>("StartDate");
            Assert.That(StartDate, Is.Not.Null);
        }
        
    }
}